/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aviso.facade;

import aviso.entity.Area;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author avgusti
 */
@Stateless
public class AreaFacade extends AbstractFacade<Area> {

    @PersistenceContext(unitName = "aviso")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public AreaFacade() {
        super(Area.class);
    }

    public List<Area> lookUp(String query) {
        return em.createNamedQuery("Area.lookUp", Area.class).setParameter("query", query).getResultList();
    }

    public List<Area> lookUpByTypeId(String query, Long id) {
        return em.createNamedQuery("Area.lookUpByType", Area.class).setParameter("query", query).setParameter("typeid", id).getResultList();
    }

    public List<Area> getByName(String query) {
        return em.createNamedQuery("Area.getByName", Area.class).setParameter("query", query).getResultList();
    }

    public List<Area> lookUpChildren(Area p) {
       List<Area> al=em.createNamedQuery("Area.listByFirstParentID",Area.class).setParameter("parentid",p.getId()).getResultList();
        return al;
    }
    
}
